package com.geeguo.ebuilder.core.security.utils;

import com.geeguo.ebuilder.core.common.constants.HeaderConstants;
import com.geeguo.ebuilder.core.common.utils.ServletUtils;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;

/**
 * Token获取工具类
 */
public class TokenHelper {

    /**
     * 获取请求token
     */
    public static String getToken() {
        return getToken(ServletUtils.getRequest());
    }

    /**
     * 根据request获取请求token
     */
    public static String getToken(HttpServletRequest request) {
        String token = null;
        String authorization = request.getHeader(HeaderConstants.AUTHENTICATION);
        if (StringUtils.isNotEmpty(authorization)) {
            token = authorization;
        }
        return token;
    }
}